package com.zjm.creational.singleton.type01;

/**
 * 饿汉式（静态常量）
 */
public class SingletonTest01 {
    public static void main(String[] args) {
        System.out.println(Singleton.getInstance());
        System.out.println(Singleton.getInstance());
        System.out.println(Singleton.getInstance());
        System.out.println(Singleton.getInstance());
    }
}

class Singleton {
    // 类加载时就初始化
    private static final Singleton INSTANCE = new Singleton();

    // 构造器私有化
    private Singleton() {
    }

    // 提供公共的静态方法，返回实例对象
    public static Singleton getInstance() {
        return INSTANCE;
    }
}
